#ifndef PICGEN_H
#define PICGEN_H

#include <SDL.h>
#include <vector>
#include "Enemy.h"
#include "Werewolf.h"
#define FURTHEST_DISTANCE 400
#define CLOSEST_DISTANCE 50
extern SDL_Surface* screen;

#include <fstream>
extern std::ofstream Debug;
class Picgen{
public:
    SDL_Surface* mypicture;
    SDL_Surface* bestpicture;
    int size;
    int bestscore;
    int newscore;
    std::vector<EnemyType> queue;
    Picgen():mypicture(0),bestpicture(0),size(0),bestscore(0),newscore(0)
    {
    }

    ~Picgen()
    {
        if(mypicture != NULL) SDL_FreeSurface(mypicture);
        if(bestpicture != NULL) SDL_FreeSurface(bestpicture);
    }

    void New(int width=150, int height=64){
        if(mypicture != NULL && mypicture != bestpicture) SDL_FreeSurface(mypicture);
        size =0;
        mypicture = SDL_CreateRGBSurface(screen->flags,width,height,screen->format->BitsPerPixel,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,screen->format->Amask);
        queue.resize(0);
    }
    void Insert(Enemy* enemy, int distance){
        size++;
        queue.push_back(enemy->type);
    }
    void Points()
    {
        //TODO: give more points for doubles, triples ps checkem
        int sum = 0;
        for(unsigned int i = 0; i < queue.size(); i++)
        {
            switch(queue[i]){
                case WEREWOLF:
                sum += 500;
                break;
                case GHOST:
                    sum+= 500;
                    break;
                case ZOMBIE:
                    sum+=500;
                    break;
                default:
                    break;
            }
        }
        newscore = sum;
//        if(newscore>bestscore){
//        bestscore = newscore;
//        SDL_Rect pos;
//        pos.x = 474; pos.y = screen->h-100+27;
//        Draw(pos);
//        bestpicture = SDL_CreateRGBSurfaceFrom(mypicture->pixels,mypicture->w,mypicture->h,mypicture->format->BitsPerPixel,mypicture->pitch,mypicture->format->Rmask,mypicture->format->Gmask,mypicture->format->Bmask,mypicture->format->Amask);
//        }
    }
    void Draw(SDL_Rect pos)
    {
//        if(size>0){
//        SDL_Rect temppos;
//        int spacing = mypicture->w/size;
//        SDL_BlitSurface(picbg,NULL,screen,&pos);
//        for(unsigned int i = 0; i < queue.size(); i++)
//        {
//            temppos = pos;
//            temppos.x += i*spacing;
//            switch(queue[i]){
//                case WEREWOLF:
//                SDL_BlitSurface(mypicture,NULL,Werewolf::mugshot,&temppos);
//                break;
//                default:
//                    break;
//            }
//        }
//        }
    }
};
#endif
